package clusterMaker;

import clusterMaker.BaseData;

public class DistanceMatrix {
	protected double matrix[][];

	protected int[] idx;
	
	
	public DistanceMatrix(BaseData data) {
		this(data, null);
	}
	
	
	public DistanceMatrix(BaseData data, int[] idx) {
		this.matrix = data.getDistanceMatrix();
		
		if (idx == null) {
			// initialize indexing array to original order
			idx = new int[matrix.length];
			for (int i = 0; i < matrix.length; ++i) {
				idx[i] = i;
			}
		}
		this.idx = idx;
	}

	private DistanceMatrix(double[][] matrix, int[] idx) {
		this.matrix = matrix;
		this.idx = idx;
	}

	
	//Get value at specified position.
	public double getValue(int i, int j) {
		return matrix[ idx[i] ][ idx[j] ];
	}
	
	//Subset distance matrix.
	public DistanceMatrix subset(int[] idx) {
		return new DistanceMatrix(this.matrix, idx);
	}

	//Getter for size of array.
	public int size() {
		return idx.length;
	}
	
}
